package com.demo.api.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.dubbo.config.annotation.Service;
import com.demo.api.UserServiceApi;
import com.demo.entity.User;
import com.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author ：qilong sun
 * @date ：Created in 2020/7/20 14:24
 * @description：
 * @modified By：
 * @version: V1.0$
 */
@Service
public class UserServiceApiImpl implements UserServiceApi {
    @Autowired
    UserService userService;

    @SentinelResource(blockHandler = "exceptionHandler")
    @Override
    public User getUser(Long uid) {
        User user = userService.getUser(uid);
        user.setName("我是sentinel-dubbo-user-provider-02");
        return user;
    }

    public String exceptionHandler(Long uid, BlockException e) {
        e.printStackTrace();
        return "错误发生在" + uid;
    }
}
